/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package exercicio_54;

import java.net.*;
import java.io.*;
import java.util.ArrayList;

/**
 *
 * @author manelv8
 */
public class Exc54 {

 

    public  ArrayList<String> verificaPorta(String site, int portas[]) {

       ArrayList<String> retorno = new ArrayList<String>();

       
        for (int i = 0; i < portas.length; i++) {
            try {

                Socket socket = new Socket();
                InetSocketAddress isa = new InetSocketAddress(site, portas[i]);
                socket.connect(isa, 10);
                System.out.println("passou");
                retorno.add("porta "+ portas[i] + " ok!");


            } catch (SocketTimeoutException e) {
                // TODO: handle exception
                System.out.println("nao passou");
                retorno.add("porta "+ portas[i] + " FAIL!");
            } catch (IOException ex) {
                // System.out.println("porta "+portas[i] +" ok");
                System.out.println("ERRO AO CONECTAR COM O SERVIDOR!");
                retorno.add("porta "+ portas[i] + " ERRO AO CONECTAR COM O SERVIDOR!");
            }

        }
        
        return  retorno;
    }
}
